<?php
/**
 * @author 
 * @copyright 2013
 */
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 
class Base_model extends CI_Model
{
	function __construct(){
		parent::__construct('');            
	}
    public function getDepatment(){
		return $this->model->table('depatment')->where('isdelete',0)->find_combo('depatmentid','depatmentname');		
	}
	public function getDepatmentCombo(){
		return $this->model->table('depatment')->where('isdelete',0)->find_combo('depatmentid','depatmentname','Chọn phòng ban...');		
	}
	public function getGroup(){
		return $this->model->table('groups')->where('isdelete',0)->order_by('groupname','ASC')->find_combo('id','groupname');		
	}
	public function getGroupCombo(){
		return $this->model->table('groups')->where('isdelete',0)->order_by('groupname','ASC')->find_combo('id','groupname','Chọn nhóm quyền...');		
	}
	public function getCity(){
		return $this->model->table('city')->where('isdelete',0)->find_combo('id','cityname');		
	}
	public function getFrom(){
		return $this->model->table('city')->where('isdelete',0)->find_combo('id','cityname','Chọn nơi đi...');		
	}
	public function getTo(){
		return $this->model->table('city')->where('isdelete',0)->find_combo('id','cityname','Chọn nơi đến...');		
	}
	public function getVehicletype($none=''){
		
		if($none =='none'){
			return $this->model->table('vehicletype')->where('isdelete',0)->find_combo('typeid','typename');		
		}
		else{
			return $this->model->table('vehicletype')->where('isdelete',0)->find_combo('typeid','typename','Chọn loại xe...');		
		}		
	}
	public function getUser($sql='',$kieuthucthi=''){
		//thuc hien webservice
		$link = $this->config['linksoap'];
		//$this->load->helper('nusoap');
		$this->CI->load->helper('nusoap');
		//$sql="SELECT `id`, `ten` FROM (`trungtam`) WHERE `thungrac` = 0";
		$param = array('sql' => $sql, 'db' => 'quanlyuser');
		$client = new nusoap_client($link);
		//////////////////////////////////
		$client->setCredentials("viettel", "viettel@1234", "basic");

		/////////////////////////////////
		$client->soap_defencoding = 'UTF-8';
		$client->decode_utf8 = false;
		if($kieuthucthi=='get'){
			$response = $client->call('getdata', $param);
			if($client->fault){
				$linkphu = $this->config['linksoapphu'];
				$clients = new nusoap_client($linkphu);
				//////////////////////////////////
				$clients->setCredentials("viettel", "viettel@1234", "basic");
		
				/////////////////////////////////
				$clients->soap_defencoding = 'UTF-8';
				$clients->decode_utf8 = false;
				$responsephu = $clients->call('getdata', $param);
				if($clients->fault){
					return "FAULT: <p>Code: (".$clients->faultcode.")</p>String: ".$clients->faultstring;
				}
				else
					return $responsephu;
			}
			else{
				return $response;
			}
		}
		else{	//print_r($sql);exit;
			$response = $client->call('sqlexecute', $param);
		//=============S upadte du lieu vao them database du phong=====================
			$linkphu = $this->config['linksoapphu'];
			$clients = new nusoap_client($linkphu);
			$clients->soap_defencoding = 'UTF-8';
			$clients->decode_utf8 = false;
			$responsephu = $clients->call('sqlexecute', $param);
       //=============E upadte du lieu vao them database du phong=====================
			if($client->fault){
				return "FAULT: <p>Code: (".$client->faultcode.")</p>String: ".$client->faultstring;
			}
			else
			{
				return $response;
			}
	//		print_r($param['sql']);exit;
		}
	} 
 }